package cn.smile.controller.basic;

import cn.smile.bean.dto.basic.VoucherDTO;
import cn.smile.bean.form.basic.voucher.AddVoucherForm;
import cn.smile.bean.form.basic.voucher.QueryVoucherForm;
import cn.smile.bean.form.basic.voucher.UpdateVoucherForm;
import cn.smile.business.basic.IVoucherService;
import cn.smile.commons.response.MyResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/voucher")
public class VoucherController {

    @Resource
    private IVoucherService service;

    @PostMapping(value = "addVoucher")
    public MyResult<Boolean> addVoucher(@Valid @RequestBody AddVoucherForm form) {
        return MyResult.OK(service.addEntity(form));
    }

    @PostMapping(value = "updateVoucher")
    public MyResult<Boolean> updateVoucher(@Valid @RequestBody UpdateVoucherForm form) {
        return MyResult.OK(service.updateEntity(form));
    }

    @PostMapping(value = "getPage")
    public MyResult<IPage<VoucherDTO>> getPage(@RequestBody QueryVoucherForm form) {
        return MyResult.OK(service.getPage(form));
    }

    @PostMapping(value = "getList")
    public MyResult<List<VoucherDTO>> getList(@RequestBody QueryVoucherForm form) {
        return MyResult.OK(service.getList(form));
    }

    @GetMapping(value = "getVoucherById")
    public MyResult<VoucherDTO> getById(@RequestParam("id") String id) {
        return MyResult.OK(service.getVoucherById(id));
    }

    @GetMapping(value = "delVoucher")
    public MyResult<Boolean> delVoucher(@RequestParam("id") String id) {
        return MyResult.OK(service.delVoucher(id));
    }
}
